package org.devlabs35.javamail;

import java.util.Properties;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;

public class ConnUtil {
	// Setup the connection information
	private static String host = "localhost";
	private static String username = "sairam35@devlabs.mail.org";
	private static String password = "sairam35";
	private static Folder folder;
	private static Store store;

	public static Message[] getMessages() throws MessagingException {
		// Create a mail session
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);

		// Create a POP3 store and connect to it
		store = session.getStore("pop3");
		store.connect(host, username, password);

		// Open the INBOX
		folder = store.getFolder("INBOX");
		folder.open(Folder.READ_ONLY);

		return folder.getMessages();
	}

	public static void closeResources() throws MessagingException {
		folder.close(false);
		store.close();
	}
}
